<!DOCTYPE html>
<html lang="zh-CN">
<head>

<#include "bases/global_style.ftl"> 
<#include "bases/global_js.ftl">
<#include "bases/combo.ftl">
</head>

<body>
 
	<div class="page-container" id="loading">

				<div class="row-fluid">
					<div class="span12">
						<div class="portlet box green">
							<div class="portlet-title">
								<div class="caption">
									<i class="fa fa-cogs"></i><#if id??>修改优惠券<#else>新增优惠券</#if>
								</div>
	                            <div class="tools">
	                                <a href="javascript:window.location.reload()" class="reload"></a>
	                            </div>
							</div>

							<div class="portlet-body flip-scroll">
  		
						  		<form class="form-horizontal" role="form" id="dataform">
						  		
						  		       <input type="hidden"   name="id" value="<#if couponModel.id??>${couponModel.id}</#if>">
									   
									   <div class="form-group">
									    <label class="col-sm-4 control-label">优惠券名称<span class="fill-must">*</span></label>
									    <div class="col-sm-5">
									        <input type="text" class="form-control"  placeholder="" name="name"  value="<#if couponModel.name??>${couponModel.name}</#if>" required>
									    </div>
									  </div>
									 
									 <div class="form-group">
									    <label class="col-sm-4 control-label">金额(元)<span class="fill-must">*</span></label>
									    <div class="col-sm-5">
									       <input type="text" class="form-control"  placeholder=""  onchange="$(this).next().val($(this).val()*100)" value="<#if couponModel.amount??>${couponModel.amount/100}</#if>" required/>
										   <input type="hidden" name="amount" value="<#if couponModel.amount??>${couponModel.amount}</#if>"> 
									    </div>
									  </div>
									  
			
									  <div class="form-group">
									    <label class="col-sm-4 control-label">使用条件<span class="fill-must">*</span></label>
									    <div class="col-sm-8">
									        <label class="radio-inline">
											  <input type="radio" name="conditionRadio"  value="1" required <#if couponModel.conditionRadio??><#if couponModel.conditionRadio==1>checked</#if></#if>   onclick="$('#conditionNum_deci').removeAttr('required')"> 不限
											</label>
											
											<label class="radio-inline">
											  <input type="radio" name="conditionRadio"  value="2" style="margin-top: 10px;" required <#if couponModel.conditionRadio??><#if couponModel.conditionRadio==2>checked</#if></#if>   onclick="$('#conditionNum_deci').attr('required','required')"> 满
											  
											  <input type="text"  onchange="$(this).next().val($(this).val()*100)" class="form-control sheet-searchInput2"  id="conditionNum_deci" name="conditionNum_deci" 
											   value="<#if couponModel.conditionNum??><#if couponModel.conditionNum gt 0>${couponModel.conditionNum/100}</#if></#if>" <#if couponModel.conditionRadio??><#if couponModel.conditionRadio==2>required</#if></#if>> 元可使用
										      
										      <input type="hidden" name="conditionNum" value="<#if couponModel.conditionNum??><#if couponModel.conditionNum gt 0>${couponModel.conditionNum}</#if></#if>">
											</label>
									    </div>
									  </div>
									  
									  
									<!--   <div class="form-group">
									    <label class="col-sm-4 control-label">车型<span class="fill-must">*</span></label>
									    <div class="col-sm-8">
											  <select id="cartypes" multiple="multiple" name="cartypes" required>
											  </select>
									    </div>
									  </div>
		 
									  
									  <div class="form-group">
									    <label class="col-sm-4 control-label">地区<span class="fill-must">*</span></label>
									    <div class="col-sm-8">
									        <label class="radio-inline">
											  <input type="radio" name="areaRadio" id="" value="1" required <#if couponModel.areaRadio??><#if couponModel.areaRadio==1>checked</#if></#if> onclick="$('#provinceids').removeAttr('required');$('#cityids').removeAttr('required')"> 全地区
											</label>
									    </div>
										    
									    <div class="col-sm-offset-4 col-sm-8">
											  <label class="radio-inline">
												  <input type="radio" name="areaRadio" id="" value="2" required <#if couponModel.areaRadio??><#if couponModel.areaRadio==2>checked</#if></#if> onclick="$('#provinceids').attr('required','required');$('#cityids').attr('required','required')"> 选择地区
											  </label>
											  
										      <div style="margin-top: 20px"></div>
											  <label class="radio-inline">省份
												  <select id="provinceids" multiple="multiple" name="provinceids" >
												  </select>
											  </label>
									
											   <div style="margin-top: 20px"></div>
											   <label class="radio-inline">地市
												  <select id="cityids" multiple="multiple"  name="cityids">
												 </select>
											  </label>
									      </div>
									   </div>-->
										  
										  						  									  
									  <div class="form-group">
									        <label class="col-sm-4 control-label">手动分配优惠券<span class="fill-must">*</span></label>
									        <div class="col-sm-8">
									             <label class="radio-inline">
											     <input type="radio" name="point"  value="1" required <#if couponModel.point??><#if couponModel.point==1>checked</#if></#if>>是
											</label>
											 </div>
											 <div class="col-sm-offset-4 col-sm-8">
											     <label class="radio-inline">
											     <input type="radio" name="point"  value="0"   required <#if couponModel.point??><#if couponModel.point==0>checked</#if></#if>>否
											</label>
											</div>
									  </div>
									  
										  
									  <div class="form-group">
									    <label class="col-sm-4 control-label">使用时效<span class="fill-must">*</span></label>
									    <div class="col-sm-8">
									        <label class="radio-inline">
											  <input type="radio" name="effecttimeRadio"   value="1" required <#if couponModel.effecttimeRadio??><#if couponModel.effecttimeRadio==1>checked</#if></#if> onclick="$('#usebegindate').removeAttr('required');$('#useenddate').removeAttr('required')"> 不限
											</label>
											<label class="radio-inline">
											  <input type="radio" name="effecttimeRadio" id="" value="2" style="margin-top: 10px;" required <#if couponModel.effecttimeRadio??><#if couponModel.effecttimeRadio==2>checked</#if></#if> onclick="$('#usebegindate').attr('required','required');$('#useenddate').attr('required','required')"> 从
											 
											  <input type="text" class="form-control sheet-searchInput2" placeholder="" name="usebegindate" id="usebegindate"  onFocus="WdatePicker({ dateFmt: 'yyyy-MM-dd HH:mm:ss' })" 
											  value="<#if couponModel.usebegindate??>${couponModel.usebegindate}</#if>" <#if couponModel.effecttimeRadio??><#if couponModel.effecttimeRadio==2>required</#if></#if>> 至
								  			  <input type="text" class="form-control sheet-searchInput2" placeholder="" name="useenddate"  id="useenddate" onFocus="WdatePicker({ dateFmt: 'yyyy-MM-dd HH:mm:ss' })"       
								  			  value="<#if couponModel.useenddate??>${couponModel.useenddate}</#if>"     <#if couponModel.effecttimeRadio??><#if couponModel.effecttimeRadio==2>required</#if></#if>>
											
											</label>
									    </div>
									  </div>
									  
									  <div class="form-group">
									    <label class="col-sm-4 control-label">生效时间<span class="fill-must">*</span></label>
									    <div class="col-sm-5">
											   <input type="text" class="form-control" placeholder="请选择生效时间" onFocus="WdatePicker({ dateFmt: 'yyyy-MM-dd HH:mm:ss' })" name="begintime" required value="<#if couponModel.begintime??>${couponModel.begintime}</#if>">
									    </div>
									  </div>
									  
									  <div class="form-group">
									    <label class="col-sm-4 control-label">截止时间<span class="fill-must">*</span></label>
									    <div class="col-sm-5">
									      <input type="text" class="form-control" placeholder="请选择生效时间" onFocus="WdatePicker({ dateFmt: 'yyyy-MM-dd HH:mm:ss' })" name="endtime" required value="<#if couponModel.endtime??>${couponModel.endtime}</#if>">
									    </div>
									  </div>
									  
									  <div class="form-group">
									    <label class="col-sm-4 control-label">使用说明</label>
									    <div class="col-sm-5">
									      <textarea class="form-control" rows="3" placeholder="" name="comment"><#if couponModel.comment??>${couponModel.comment}</#if></textarea>
									    </div>
									  </div>
									  
								  <div class="form-group">
								    <div class="col-sm-offset-4 col-sm-5 sheet-btnBar">
								      <button type="button" class="btn btn-info sheet-btn" onclick="submitFormdata()">保存</button>
								      <button type="button" class="btn btn-default sheet-btn" onclick="closeDialog()">取消</button>
								    </div>
								  </div>
								  
								  <div class="form-group" style="display: none">
								    <div class="col-sm-offset-4 col-sm-5 error-resgister">
										<span id="errorContent">错误提示错误提示错误提示</span><!-- 错误提示 -->
									</div>
								  </div>
								</form>
							</div>
						</div>
					</div>
				</div>
			</div>
			
<script> 
	$(document).ready(function() {
 
	    
	    dataform=$("#dataform").validate();
	 	selectEvent();//下拉框多选
	 	
	    $('#cartypes').val('<#if couponModel.cartypes??>${couponModel.cartypes}</#if>'.split(","));
        $('#cartypes').multiselect("refresh");  
	    $('#provinceids').val('<#if couponModel.provinceids??>${couponModel.provinceids}</#if>'.split(","));
        $('#provinceids').multiselect("refresh");  
	    $('#cityids').val('<#if couponModel.cityids??>${couponModel.cityids}</#if>'.split(","));
        $('#cityids').multiselect("refresh");  
	});

 
	  
	  function selectEvent(){
		  
		  /*  combox("cartypes","CarType",null,null,true);
	  		 $("#cartypes").multiselect({
		  			noneSelectedText: "===请选择===",
		  			checkAllText:"全选",
		  			uncheckAllText:"全不选",
		  		    selectedText: "选中【#】项 ,共【 #】项"
		     });*/

	  		 
		    combox("provinceids","Province",null,null,true);
		    $("#provinceids").multiselect({
	  			noneSelectedText: "===请选择===",
	  			checkAllText:"全选",
	  			uncheckAllText:"全不选" ,
	  			uncheckAll: function(event, ui){
	  				setCitymultiselect();
	  	        },
	  			selectedText:function(numChecked, numAll, chkItems) {
	  				setCitymultiselect();
	  				return "选中【"+numChecked+"】项 ,共【 "+numAll+"】项";
	  	        }
	  	        
	  		});
		    setCitymultiselect();
	  }
	  
	  
	  function setCitymultiselect(){
			    var provincesids= $("#provinceids").multiselect().multiselect("getChecked").map(function() {
	                return this.value;
	            }).get();
				
				 $("#cityids").multiselect().multiselect("destroy").hide();
				 combox("cityids","City",provincesids,null,true);
		  		 $("#cityids").multiselect({
		  			noneSelectedText: "===请选择===",
		  			checkAllText:"全选",
		  			uncheckAllText:"全不选",
		  		    selectedText: "选中【#】项 ,共【 #】项"
		  		 });
	  }
	  
	  var dataform;
	  function submitFormdata(){
		  
		     var task=getUrlParamVal('task');
		     
		     dataform.form();
    	     if(dataform.valid()){
                var a,url;
                var nowtime = new Date();
                var strtemp = ""+nowtime.getHours()+nowtime.getMinutes()+nowtime.getSeconds()+nowtime.getMilliseconds();
                a=strtemp;

                if(task=='add'){
                	url= "${base}/add_coupon/" + a;
                }else if(task=='edit'){
                	url= "${base}/edit_coupon";
                }
                
                $("#loading").showLoading(); 
        		$.ajax({  
	      		      type : "POST",  
	      		      url : url,
	      		      dataType : "json",  
	      		      data:  $("#dataform").serialize(),
	      		      success : function(data) {  
	      		       	    $('#loading').hideLoading();
		      		        if(data.result == true) {
	   
		      			         jAlert("操作成功！","提示", function() {
		      			            parent.window.opener.location.reload();
		                            closeDialog();
		      		             });
	                           
	                        }else if(data.result == false){
	                        	 jAlert("未知错误！");
	                        }
	                        	
	      		      }  
      		    }); 	    	
    	    }
		  
	  }
	  
</script>
</body>